#!/bin/ash -efu
#
# mki-pack-boot
#
# This file is part of mkimage
# Copyright (C) 2007-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

. "${0%/*}"/mki-sh-functions

verbose "has started executing."

BOOT_TYPE="${BOOT_TYPE:?boot type required}"

outname="${MKI_OUTNAME:-outname}"
outname="${outname##*/}"

types=
for b in ${BOOT_TYPE:-}; do
	case "$b" in
		isolinux|pxelinux|syslinux|efiboot|ieee1275boot|grubaa64boot|grubpcboot) types="$types $b " ;;
		*) fatal "Unknown boot type" ;;
	esac
done

[ -z "${EFI_BOOTLOADER:-}" ] || [ -z "${types##* grubaa64boot *}" ] || [ -z "${types##* efiboot *}" ] ||
	types="$types efiboot "

[ -n "$types" ] ||
	fatal "Boot type required"

[ -d "$chroot" ] ||
	fatal "$dir: not look like a work directory of hasher."

[ -z "${PROPAGATOR_MAR_MODULES:-}" ] ||
	mki-build-propagator

for b in $types; do
	mki-copy-$b
done

[ -n "${types##* isolinux *}" ] ||
	exec mki-pack-isoboot

[ -n "${types##* grubpcboot *}" ] ||
	exec mki-pack-grubpc-isoboot

[ -n "${types##* ieee1275boot *}" ] ||
	exec mki-pack-isodata

[ -n "${types##* grubaa64boot *}" ] ||
	exec mki-pack-efionly-isoboot

[ -z "${types##* isolinux *}" ] || [ -z "${types##* grubpcboot *}" ] || [ -n "${types##* efiboot *}" ] ||
	exec mki-pack-efionly-isoboot

exec mki-pack-data
